<?php
/**
 * Created by PhpStorm.
 * User: yuyj
 * Date: 16-11-11
 * Time: 上午11:48
 */

namespace mybackend\controllers;


use common\services\common\MyscrmMaintainerAccountService;
use Yii;
use yii\helpers\Json;

class MaintainerAccountController extends BaseController
{

    protected $_service;

    public function __construct($id, $module, MyscrmMaintainerAccountService $service, $config = [])
    {
        $this->_service = $service;
        parent::__construct($id, $module, $config);
    }

    /**
     * 获取所有绑定的账号
     */
    public function actionGetAllBindAccounts()
    {
        $data = $this->_service->getAllBindAccounts();

        return $this->json([
            "retCode" => $this->_service->getErrCode(),
            "msg"     => $this->_service->getErrMsg(),
            "data"    => $data,
        ]);
    }

    /**
     * 绑定账号
     */
    public function actionBatchBindAccount()
    {
        $raw_input = Json::decode(Yii::$app->request->getRawBody()) ;

        $data = $this->_service->batchBindAccount($raw_input);

        return $this->json([
            "retCode" => $this->_service->getErrCode(),
            "msg"     => $this->_service->getErrMsg(),
            "data"    => $data,
        ]);
    }
}